#pragma once

#include "nlohmann/json.hpp"
#include "uuid.hpp"
#include <optional>
#include <string>

class Strategy {
    std::string _strategy;
    std::optional<std::size_t> _param;
    std::string _uuid;

public:
    bool hasParam(void) const { return _param.has_value(); }
    bool isLoopStrategy(void) const { return _strategy == "loop"; }
    bool isChangeStrategy(void) const { return _strategy == "change"; }
    bool isBootStrategy(void) const { return _strategy == "boot"; }
    bool isRegularStrategy(void) const { return _strategy == "regular"; }
    std::string uuid(void) const { return _uuid; }

    std::size_t param(void) const { return _param.value(); }
    std::string strategy(void) const { return _strategy; }

public:
    Strategy() = default;
    Strategy(const std::string &strategy)
        : _strategy(strategy) {}
    Strategy(const std::string &strategy, std::size_t time)
        : _strategy(strategy), _param(time) {}

    friend void from_json(const nlohmann::json &j, Strategy &s) {
        if (j.contains("strategy")) {
            j.at("strategy").get_to(s._strategy);
        }

        if (j.contains("param") && j.at("param").is_number_integer()) {
            s._param = j.at("param").get<std::size_t>();
        }

        if (s.isLoopStrategy()) {
            s._uuid = Uuid::generate();
        }
    }
};
